package elcom.control.processor;

import elcom.model.common.Log;
import elcom.model.data.QueueIO;
import elcom.model.data.Student;

public class ProcessorMain extends Thread {
	private QueueIO<Student> queIn = null;
	private QueueIO<String> queOut = null;
	private static QueueIO<ThreadNew> queTin = new QueueIO<>();

	public ProcessorMain(QueueIO<Student> queIn, QueueIO<String> queOut) {
		this.queIn = queIn;
		this.queOut = queOut;
	}

	@Override
	public void run() {
		for (int i = 0; i < 10; i++) {
			Processor pr = new Processor(queTin, queIn, queOut);
			pr.setName("Processor_" + i);
			pr.start();
		}
		while (true) {
			if (queTin.size() > 0) {
				ThreadNew td = queTin.getFirst();
				if (td != null) {
					td.resumed();
					synchronized (queIn) {
						queIn.notifyAll();
					}
					queTin.remove(td);
				}
			}
			try {
				sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
				Log.logErr(e.toString());
			}
		}
	}
}
